/// Created by RongCheng on 2022/7/26.

import 'package:flutter/material.dart';

import 'notifier/notification.dart';

/// 被拖拽的 widget (是个覆盖全屏的页面)
class DragGestureDetector extends StatelessWidget {
  const DragGestureDetector({
    Key? key,
    required this.child,
    this.onPanStart,
    this.onPanUpdate,
    this.onPanEnd,
    this.onPanCancel,
    this.onTap,
  }) : super(key: key);
  final Widget child;
  final Function? onPanStart;
  final Function? onPanUpdate;
  final Function? onPanEnd;
  final Function? onPanCancel;
  final Function? onTap;
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onPanStart: (DragStartDetails details) {
        DragOnPanStartNotification(details).dispatch(context);
        onPanStart?.call();
      },
      onPanUpdate: (DragUpdateDetails details) {
        DragOnPanUpdateNotification(details).dispatch(context);
        onPanUpdate?.call();
      },
      onPanEnd: (DragEndDetails details) {
        DragOnPanEndNotification(details).dispatch(context);
        onPanEnd?.call();
      },
      onPanCancel: () {
        const DragOnPanCancelNotification().dispatch(context);
        onPanCancel?.call();
      },
      onTap: () {
        const DragOnTapNotification().dispatch(context);
        onTap?.call();
      },

      //双指缩放功能
      // onScaleStart: (ScaleStartDetails details) {},
      // onScaleUpdate: (ScaleUpdateDetails details) {
      //   if (details.scale == 1) {
      //     print("单指${details.scale}");
      //   } else {
      //     print("双指${details.scale}");
      //   }
      // },

      // onScaleEnd: (ScaleEndDetails details) {},

      child: child,
      //InteractiveViewer
      /// 只有[child]会被响应拖拽事件
    );
  }
}
